<%@page contentType="text/html;charset=utf-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <jsp:include page="common.jsp"/>
    <style type="text/css">
        .cque-list {
            margin: 10px;
            display: flex;
            flex-direction: column;
        }

        .cque-list-nav {
            margin: 10px;
        }

        .cque-list-content {
            margin: 10px;
        }

        .cque-td {
            display: flex;
            justify-content: space-around;
            align-items: center;
        }
th{
    text-align: center;
}tr{
     text-align: center;
 }
    </style>
</head>

<body>
<div class="cque-window">
    <div class="cque-nav">
        <div class="navbar-header" style="margin-left: 20px">
            <img alt="Brand" height="60px" src="${pageContext.request.contextPath}/assets/images/logo.png">
        </div>
        <h2 style="margin-left: 20px">商城后台管理系统</h2>
    </div>
    <div class="cque-content">
        <div class="cque-side">
            <div class="panel panel-info" style="margin: 0;height: 100%">
                <a href="/admin/category/list"><div class="panel-heading" style="background-color:#d9edf7;">系统菜单</div></a>
                <div class="panel-body" style="padding: 0">
                    <div class="list-group">
                        <a href="/admin/category/list" class="list-group-item">商品类别管理</a>
                        <a href="/admin/product/list" class="list-group-item">商品管理</a>
                        <a href="/admin/order/list" class="list-group-item" style="background-color:#d9edf7;">订单管理</a>
                    </div>
                </div>
            </div>
        </div>
        <div class="cque-main">
            <div class="cque-list">
                <div class="cque-list-content">
                    <table class="table table-bordered" cellpadding="0">
                        <thead>
                        <tr>
                            <th class="col-md-1">编号</th>
                            <th class="col-md-1">订单时间</th>
                            <th class="col-md-1">总价</th>
                            <th class="col-md-1">状态</th>
                            <th class="col-md-1">邮寄地址</th>
                            <th class="col-md-1">收件人</th>
                            <th class="col-md-1">收件人电话</th>
                            <th class="col-md-1">订单所属账户id</th>
                            <th class="col-md-1">操作</th>

                        </tr>
                        </thead>
                        <tbody>
                            <c:forEach items="${orderList}" var="list">
                            <tr>
                                <td class="col-md-1">${list.id}</td>
                                <td class="col-md-1">${list.createTime}</td>
                                <td class="col-md-1">${list.total}</td>
                                <td class="col-md-1">${list.state}</td>
                                <td class="col-md-1">${list.address}</td>
                                <td class="col-md-1">${list.name}</td>
                                <td class="col-md-1">${list.telephone}</td>
                                <td class="col-md-1">${list.uid}</td>
                                <td class="cque-td">
                                    <button type="button" class="update btn btn-default " data-toggle="modal"
                                            data-target="#myModal" > 修改
                                    </button>
                                    <button class="btn btn-default" onclick="del(`${list.id}`)" type="button">删除</button>
                                </td>
                            </tr>
                        </c:forEach>


                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<%--修改model--%>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">修改订单</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal ">
                    <div class="form-group">
                        <label for="oid" class="col-sm-offset-1 col-sm-3 control-label">订单ID</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="oid"
                                   readonly="readonly">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="ordertime" class="col-sm-offset-1 col-sm-3 control-label">订单创建时间</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="ordertime" readonly="readonly">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="total" class="col-sm-offset-1 col-sm-3 control-label">订单总价</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="total"  readonly="readonly">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="state" class="col-sm-offset-1 col-sm-3 control-label">订单状态</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="state"  readonly="readonly">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="address" class="col-sm-offset-1 col-sm-3 control-label">收货地址</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="address" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="name" class="col-sm-offset-1 col-sm-3 control-label">收货人</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="name" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="telephone" class="col-sm-offset-1 col-sm-3 control-label">收货电话</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="telephone" >
                        </div>
                    </div>



                    <div class="form-group">
                        <label for="uid" class="col-sm-offset-1 col-sm-3 control-label"  readonly="readonly">订单账户ID</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="uid" readonly="readonly">
                        </div>
                    </div>

                </form>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" onclick="save()">保存</button>
                </div>
            </div>
        </div>
    </div>
</div>


<script>
    $('.update').click(function () {
        var oid = $(this).parent().parent().children().eq(0).text();
        var ordertime = $(this).parent().parent().children().eq(1).text();
        var total = $(this).parent().parent().children().eq(2).text();
        var state = $(this).parent().parent().children().eq(3).text();
        var address = $(this).parent().parent().children().eq(4).text();
        var name = $(this).parent().parent().children().eq(5).text();
        var telephone = $(this).parent().parent().children().eq(6).text();
        var uid = $(this).parent().parent().children().eq(7).text();
        $('#oid').val(oid);
        $('#ordertime').val(ordertime);
        $('#total').val(total);
        $('#state').val(state);
        $('#address').val(address);
        $('#name').val(name);
        $('#telephone').val(telephone);
        $('#uid').val(uid);

    })

    function del(oid) {
        console.log(oid)
        if (confirm('是否确认删除?')) {
            $.post('/admin/order/del', {oid:oid}, function (result) {
                if(result.code===1){
                    location.href='/admin/order/list'
                }
            })
        } else {
            return false;
            location.href = '/admin/order/list'
        }
    }
    
    function save() {
        var oid = $('#oid').val();
        var name =$('#name').val();
        var address =$('#address').val();
        var telephone =$('#telephone').val();
        $.post('/admin/order/updates',{oid:oid,name:name,address:address,telephone:telephone},function (result) {
            if(result.code===1){
                location.href = '/admin/order/list'
            }else {
                alert('修改失败，请重试...')
                location.href = '/admin/order/list'
            }
        })
    }
</script>
</body>
</html>